package com.victor9ac.mashup.es.threadpool.task;


import org.springframework.stereotype.Component;

import com.victor9ac.mashup.api.MashupDataType;
import com.victor9ac.mashup.elasticsearch.tasks.ElasticSearchOperation;


public class MashupElasticSearchTask implements Runnable {

	
	private ElasticSearchOperation elasticSearchOperation;
	private MashupDataType mashupDataType;

	private Object obj;
	private String indexName;
	
	
	public MashupElasticSearchTask() {
		super();
		// TODO Auto-generated constructor stub
	}

	public MashupElasticSearchTask(ElasticSearchOperation elasticSearchOperation,MashupDataType mashupDataType,String indexName,Object obj) {
		super();
		this.elasticSearchOperation = elasticSearchOperation;
		this.mashupDataType = mashupDataType;
		this.indexName = indexName;
		this.obj = obj;

	}

	public void run() {
		if (canInsertData()){
			elasticSearchOperation.setFromMyPersistence(obj, mashupDataType,indexName);
		}else{
			System.out.println("please define the data type");
		}
		
		
	}

	private boolean canInsertData() {
		return mashupDataType != null && elasticSearchOperation != null && indexName != null && !indexName.isEmpty() && obj != null;
	}
	


}
